package api

import (
	"github.com/gin-gonic/gin"
	"github.com/share309/gojwt"
	"shopcar/api/handler"
	middleware "shopcar/api/middlerware"
	"shopcar/consts"
)

func Load(r *gin.Engine) {
	r.Use(middleware.RunTime())
	r.Use(middleware.Cors())

	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/register", handler.Register)
			user.POST("/login", handler.Login)

			user.Use(gojwt.JWTAuth(consts.JWT_KEY))
			user.POST("/pertoken", handler.PerToken)
		}
		boos := api.Group("/boos")
		{
			boos.POST("/login", handler.BoosLogin)
			boos.Use(gojwt.JWTAuth(consts.JWT_KEY))
			boos.POST("/pertoken", handler.BoosPerToken)
		}

		shop := api.Group("/shop")
		{
			shop.Use(gojwt.JWTAuth(consts.JWT_KEY))
			shop.POST("/add", handler.ShopAdd)
			shop.POST("/update", handler.Update)
			shop.GET("/list", handler.ShopList)
			shop.GET("/Page", handler.ShopPage)

			shop.GET("/detail", handler.Detail)
		}

		like := api.Group("/like")
		{
			like.Use(gojwt.JWTAuth(consts.JWT_KEY))
			like.POST("/add", handler.LikeAdd)
			like.POST("/remove", handler.LikeRemove)
			like.GET("/serach", handler.LikeSearch)
		}

		comment := api.Group("/comment")
		{
			comment.Use(gojwt.JWTAuth(consts.JWT_KEY))
			comment.POST("/add", handler.CommentAdd)
			comment.POST("/del", handler.CommentDel)
		}
	}
}
